package com.yourname.bank_sim.action;

import com.yourname.bank_sim.DataStore;
import com.yourname.bank_sim.entity.Routes;
import com.yourname.bank_sim.entity.Station;

import java.util.Scanner;

public class RouteAction {
    private static Scanner scanner=new Scanner(System.in);
    private static void create(){
        System.out.println("请输入新的路线编号-路线名-[行驶车站编号]（如：R1-1号线-[1,2,3,4]）");
        String next = scanner.next();
        String[] splited=next.split("-");
        Routes routes=new Routes();
        routes.setId(splited[0]);
        routes.setName(splited[1]);
        String[] ids=splited[2].substring(1,splited[2].length()-1).split(",");
        routes.setStations(ids);
        DataStore.addRoute(routes);
        DataStore.saveData();
    }
    private static void edit(){
        System.out.println("请输入要修改的路线编号：");
        String routeNO = scanner.next();
        System.out.println("新的站名-[行驶车站编号]（如：1号线-[1,2,3,4]）");
        String next = scanner.next();
        String[] splited=next.split("-");
        Routes routes=new Routes();
        routes.setId(routeNO);
        routes.setName(splited[0]);
        String[] ids=splited[1].substring(1,splited[1].length()-1).split(",");
        routes.setStations(ids);
        DataStore.updateRoute(routes);
        DataStore.saveData();
    }
    private static void delete(){
        System.out.println("请输入要删除的车站编号：");
        String stationNO = scanner.next();
        DataStore.deleteRoute(stationNO);
        DataStore.saveData();
    }
    public static void menu(){
        while (true){
            System.out.println("""
                    1.路线创建
                    2.路线编辑
                    3.路线删除
                    4.退出
                    """);
            int i = scanner.nextInt();
            if (i==4){
                break;
            }
            switch (i){
                case 1->create();
                case 2->edit();
                case 3->delete();
            }
        }
    }
}
